home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Tools & Apps / Misc. Utilities / Installer / Installer 3.2 / Samples - Installer 3.2 / UserFunction.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-01-22  |  3.5 KB  |  144 lines  |  [TEXT/MPS ]

  1. /*------------------------------------------------------------------------------
  2.  *
  3.  *    Apple Macintosh Developer Technical Support
  4.  *
  5.  *  Installer 3.1 sample: User Functions
  6.  *
  7.  *    File:        UserFunction.c -    c Source
  8.  *
  9.  *    by:            Jon Zap
  10.  *
  11.  *    Copyright © 1988-1990 Apple Computer, Inc.
  12.  *    All rights reserved.
  13.  *
  14.  *----------------------------------------------------------------------------*/
  15. #if 0
  16. c -b UserFunction.c
  17. Link -ra =resPurgeable -rt infn=1001 -rn -m USERFUNCTION -t rsrc -c RSED ∂
  18.         UserFunction.c.o ∂
  19.         "{Libraries}"Interface.o ∂
  20.         -o UserFunction.rsrc
  21. #endif
  22.  
  23. /* applec is only defined by MPW C so we can use it to make versions that work
  24.   with MPW C and THINK C
  25.  */
  26. #ifdef applec
  27. #include    <CType.h>
  28. #include    <Quickdraw.h>
  29. #include    <Windows.h>
  30. #include    <OSUtils.h>
  31. #include    <desk.h>
  32. #include    <dialogs.h>
  33. #include    <Errors.h>
  34. #include    <Events.h>
  35. #include    <Memory.h>
  36. #include    <Menus.h>
  37. #include    <SegLoad.h>
  38. #include    <Slots.h>
  39. #include    <ToolUtils.h>
  40. #include    <Devices.h>
  41. #include    <Resources.h>
  42. #include    <SysEqu.h>
  43. #endif
  44.  
  45. #include "UserFunction.h"
  46.  
  47. #ifndef applec
  48. #define screenActive scrnActive
  49. #endif
  50.  
  51. #define kTobyBoardID 5
  52.  
  53. Boolean checkBoardID(void);
  54.  
  55. pascal Boolean UserFunction(short targetVRefNum, long blessedID, long whichFunction)
  56. {
  57. #pragma unused (blessedID, targetVRefNum)
  58.  
  59.     switch (whichFunction) {    /* switch is useless here but we assume that we'll add other userFunctions */
  60.     
  61.     case FindMyBoard: 
  62.         return checkBoardID();
  63.     }
  64. }
  65.  
  66. Boolean checkBoardID()
  67. {
  68.     int        Index,i;
  69.     OSErr        err;
  70.     int            slots[6];
  71.     GDHandle    aDev, aDevList[6];
  72.     AuxDCEHandle DCE;
  73.     int            lastDevIndex;
  74.     SInfoRecord    mySInfoRec;
  75.     SpBlock        mySpBlock;
  76.     SysEnvRec theSys;
  77.     short theBoardID;
  78.     
  79.  
  80.     err = SysEnvirons(1,&theSys);            /* should use gestalt (or even better check with a rule before calling this function) */
  81.     if (err!=noErr || !theSys.hasColorQD) {    /* without color QD this thing is irrel */
  82.         return false;
  83.         }
  84.  
  85.     /* go thru the graphics device list and get the list of active screen gdevices
  86.         and the slot numbers of their cards
  87.     */
  88.     for (Index = 0, aDev = GetDeviceList(); aDev; aDev = GetNextDevice(aDev))
  89.         if (TestDeviceAttribute(aDev,screenDevice)&&TestDeviceAttribute(aDev,screenActive))
  90.             {
  91.             aDevList[Index] = aDev;
  92.             lastDevIndex = Index;
  93.             DCE = (AuxDCEHandle) GetDCtlEntry((**aDev).gdRefNum);
  94.             slots[Index] = (**DCE).dCtlSlot; /* get the slot number */
  95.             Index++;
  96.             }
  97.     
  98.     /* go thru each of the devices/cards and see if the board id is MINE */
  99.     for (i=0; i<=lastDevIndex; i++) {
  100.         Index = slots[i];
  101.         /* init parameters for SReadInfo */
  102.         mySpBlock.spResult = (long) &mySInfoRec;
  103.         mySpBlock.spSlot = Index; /* which slot to look at */
  104.         
  105.         /* let's see if any board is in the slot */
  106.         err = SReadInfo (&mySpBlock);
  107.         if (err) {
  108.             /* report error */
  109.             continue;
  110.             }
  111.         
  112.         if (mySInfoRec.siInitStatusA == smEmptySlot) {    /* pretty weird if no card! */
  113.             continue;
  114.             }
  115.  
  116.         /* init parameters for sNextTypesRsrc, look for card info of the following type */
  117.         /* Look in slot (Index) */
  118.         mySpBlock.spSlot = Index;
  119.         mySpBlock.spID = 0;
  120.         mySpBlock.spExtDev = 0;
  121.         mySpBlock.spCategory = 1;
  122.         mySpBlock.spCType = 0;
  123.         mySpBlock.spDrvrSW = 0;
  124.         mySpBlock.spDrvrHW = 0;
  125.         
  126.         err = SNextTypeSRsrc (&mySpBlock);
  127.         
  128.         if (err) {    /* report error */
  129.             continue;
  130.             }
  131.         
  132.         /* init parameters for SReadWord */
  133.         mySpBlock.spID = 32; /* board ID */
  134.         err = SReadWord(&mySpBlock);
  135.         if (err) {    /* report error */
  136.             continue;
  137.             }
  138.         theBoardID = (mySpBlock.spResult & 0x0000FFFF);
  139.         
  140.         if (theBoardID == kTobyBoardID)
  141.             return true;
  142.         }
  143.     return false;
  144. }